#include "Texture.h"

Texture::Texture( const std::string& filename )
{
	m_filename = filename;
	m_Loaded = false;
}

Texture::Texture()
{
	m_Loaded = false;
}

void Texture::bind()
{
	if(!m_Loaded)
	{
		m_Texture = TextureLoader::getInstance().loadTexture( m_filename, this );
		m_Loaded = true;
	}

	// Went wrong?
	if( m_Texture == 0 )
	{
		printf("Cannot use texture %s\n", m_filename.c_str() );
		return;
	}

	// Bind!
	glEnable( GL_TEXTURE_2D );
	glBindTexture(GL_TEXTURE_2D, m_Texture);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}

void Texture::unbind()
{
	glDisable( GL_TEXTURE_2D );
}